using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace BodySoundSimulator.CaseData
{
    public class SoundForAuscultationConfiguration
    {
        #region Fields
        byte[] sound;
        AuscultationConfiguration configuration;
        #endregion

        #region Properties
        /// <summary>
        /// Get bytes from the sound file for saving
        /// Not saved in the map data
        /// </summary>
        public byte[] Sound
        {
            get
            {
                //Read the corresponding wave file and read it to return bytes
                return sound; 
            }
        }

        public AuscultationConfiguration Configuration
        {
            get { return configuration; }
            set { configuration = value; }
        }
        #endregion

        #region Constructor
        public SoundForAuscultationConfiguration()
        {
            this.configuration = AuscultationConfiguration.NormalBreath;
        }

        public SoundForAuscultationConfiguration(AuscultationConfiguration configuration)
        {
            this.configuration = configuration;
        }
        #endregion

        #region public methods
        public void Serialize(BinaryWriter writer)
        {
            int length = sound.Length;
            writer.Write(length);
            for (int index = 0; index < length; index++)
            {
                writer.Write(sound[index]);
            }
        }

        public void Deserialize(BinaryReader reader, float latestVersion)
        {
            int length = reader.ReadInt32();
            this.sound = new byte[length];
            for (int index = 0; index < length; index++)
            {
                this.sound[index] = reader.ReadByte();
            }
        }
        #endregion
    }
}
